$(function (global) {
    global.search = (function (search) {

        var pairs = search.slice(1).split('&');
        var result = {};
        pairs.forEach(function (pair) {
            if (pair && pair.indexOf('=') !== -1) {
                pair = pair.split('=');
                //兼容写法
                result[pair[0]] = result[
                    pair[0].toLocaleLowerCase()
                    ] = decodeURIComponent(pair[1] || '');
            }
        });
        return JSON.parse(JSON.stringify(result));
    })(location.search);
}(window));

var obj1=null;
$(document).ready(function () {
    console.log('1234');
    $.post(
        "/terminal/queryData",
        {storeId:search.storeId},
        function (data) {
            console.log(data);
            obj1=data;
            var aaaHtml = _.template($("#tp").html());
            $(".shebei").html(aaaHtml, obj1);
        }
    )
})

mui('body').on('tap', '.shanchu', function () {
    console.log('1234567');
    var terminalId= $(this).data("id");
    console.log(terminalId);
    location.href="/store/storeterminalinfo?terminalId="+terminalId;
})

mui('body').on('tap','.icon-add',function () {
    // location.href="/terminal/addstoreterminal?storeId="+search.storeId;
    ShowDiv('MyDiv', 'fade');
})

function ShowDiv(show_div, bg_div) {
    document.getElementById(show_div).style.display = 'block';
    document.getElementById(bg_div).style.display = 'block';
    var bgdivshou = document.getElementById(bg_div);
    bgdivshou.style.width = document.body.scrollWidth;
    $("#" + bg_div).height("100%");

};
//关闭弹窗
function CloseDiv(show_div, bg_div) {
    document.getElementById(show_div).style.display = 'none';
    document.getElementById(bg_div).style.display = 'none';
};

// $(".icon-add").attr("href", "../home/addpaycard.html");

mui('body').on('tap','.mydiv_show p',function () {

    event.stopPropagation();
   var terminalId=$(this).data('terminalid');
   console.log(terminalId);
   console.log(search.storeId);
    $.post(
        "/terminal/storeBing",
        {storeId:search.storeId,id:terminalId},
        function (data) {
        console.log(data);
    })
    CloseDiv('MyDiv', 'fade');
    location.href="/store/storeterminalinfo?storeId="+search.storeId;
})






